$(document).ready(function () {
	//variable para hacer las validaciones del email
	var emailreg = /^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/;
	
       $("a").click(function(e) {  
       	
		    var name = $(".name").val();
		    var email = $(".email").val();
			var password = $(".password").val();
		    var status = $(".status").val();
			 
	        $(".error").remove();
	        if(name == "" ){
	            $(".name").focus().after("<span class='error'>Ingress a name</span>");
	            return false;
	        }else if( email == "" || !emailreg.test(email) ){
	            $(".email").focus().after("<span class='error'>Ingress a correct email</span>");
	            return false;
	        }else if( password == ""){
	            $(".password").focus().after("<span class='error'>Ingress a password</span>");
	            return false;
	        }else if( status == "" ){
	            $(".status").focus().after("<span class='error'>Ingress a status</span>");
	            return false;
	        }       
	        //Si no hay errores guardo el contacto
	        Parse.$= jQuery; 
		    //Parse.initialize("cIsgepqAZm90F2mWdiJ9nP5HkrdG3nBcs98yJrVA", "CYI3htcqoz9bERjSCTpqu5FOWjhkkl72CgEenoLD");	
		   Parse.initialize("UCyMTCIXJqmFk3oLy4CwkxXv6oymztzqqoQNWAux", "BBYPhajAwBgLFzDTXvnx4MaReUn8Kke2KkwQ4yTT");
		   //Parse.initialize("gLxhWhhBK7SPLZ7Jevs6q2lcLBlhje3l3sQlyS0e", "nPvJsuTXpFeKvNyDjZg8ks8sYwt2nntVOi9hr91J");

		   var Contact = Parse.Object.extend("Contact");
			var contact = new Contact();
			 
			contact.set("name", name);
			contact.set("email", email);
			contact.set("password", password);
			contact.set("status", status);
			contact.save();
				/*	   
				$.ajax({
				  type: 'POST',
				  //headers: {'X-Parse-Application-Id':"cIsgepqAZm90F2mWdiJ9nP5HkrdG3nBcs98yJrVA",'X-Parse-REST-API-Key':"feP3mjrd24Y67cem8Xxc3QrYI0G7cst9FKmgfwJ4"},
				  //headers: {'X-Parse-Application-Id':"UCyMTCIXJqmFk3oLy4CwkxXv6oymztzqqoQNWAux",'X-Parse-REST-API-Key':"ndDxHUOCxlE5ow0HrLKnlhRUP8LaoAuT326JRSxO"},
				  headers: {'X-Parse-Application-Id':"gLxhWhhBK7SPLZ7Jevs6q2lcLBlhje3l3sQlyS0e",'X-Parse-REST-API-Key':"s8OMnEYsJAjHaqSjJWai4M7AvF0v1JvSXO4u22HD"},
				  url: "https://api.parse.com/1/classes/Contact",
				  data: JSON.stringify({
				    "name": name,
				    "email": email,
				    "password": password,
				    "status": status,
				  }),
				  contentType: "application/json"
				});*/
				document.location.href='home.html?user='+email;	
	});

    $(".name, .status, .password").keyup(function(){
        if( $(this).val() != "" ){
            $(".error").fadeOut();
            return false;
        }
    });
    
    $(".email").keyup(function(){
        if( $(this).val() != "" && emailreg.test($(this).val())){
            $(".error").fadeOut();
            return false;
           }
    });
      
});
	